Ext.define('AM.view.PerformanceGridView', {
		extend: 'Ext.grid.Panel',
		alias : 'widget.performanceGridView',
		initComponent: function(){
		Ext.apply(this,{
		store : 'PerformanceStore',
		id:'performanceGridView',
		columnLines:true,
		singleSelect:false,
	   features: [{
                ftype: 'summary'
            }],
		selModel : Ext.create('Ext.selection.CheckboxModel',{
				singleSelect:false
			}), 
//    	dockedItems: [{
//        xtype: 'pagingtoolbar',
//        dock: 'bottom',
//        store : 'PerformanceStore',
//        displayInfo: true
//        }],
		 selType:  'cellmodel',
		  plugins: [
				  Ext.create('Ext.grid.plugin.CellEditing', {
					            clicksToEdit: 1
				 })
		 ],
		columns: [
			        { text: 'ID',dataIndex: 'id',width:0,align:'center'},
			        { text: 'empID',dataIndex:'employeeid',width:0,align:'center'},
			        {text: '序号', xtype: 'rownumberer',width:50,align:'center'},
			        { text: '姓名', dataIndex: 'employee', width:80,align:'center'},
			        { text: '程序化工作',columns: [
				        	{ text:'工作总数',dataIndex: 'chengxu', width:70,align:'center',xtype: 'numbercolumn', format:'0.00'},
				        	{text:'奖金', dataIndex:'CHXUreward',width:120,align:'center',xtype: 'numbercolumn', format:'0.00',summaryType: 'sum',
				        	 summaryRenderer: function(value, summaryData, dataIndex) {
				        	 	return '合计：' + value ;
			            }
				        	}
			        ] },
			        {text: '项目化工作', columns: [
			        	{ text: '临时性工作',columns: [
				        	{ text: 'Ⅰ得分（件） ',width:100,align:'center',  xtype: 'templatecolumn',tpl: '{jinjizhongyao} ({yiji})' },
					        { text: 'Ⅱ得分（件）', width:105,align:'center',xtype: 'templatecolumn', tpl: '{jinjibuzhongyao} ({erji})'},
					        { text: 'Ⅲ得分（件）', width:105,align:'center',xtype: 'templatecolumn', tpl: '{bujinjizhongyao} ({sanji})'},
					        { text: 'Ⅳ得分（件）', width:110,align:'center',xtype: 'templatecolumn', tpl: '{bujinjibuzhongyao} ({siji})'}
			        	]},
				        { text: '总分', dataIndex: 'totalCount', width:90,align:'center',xtype: 'numbercolumn', format:'0.00',summaryType: 'sum',
					        summaryRenderer: function(value, summaryData, dataIndex) {

					                return  '合计：' + value ;
					            }
				        },
				        { text: '奖金', dataIndex:'XMreward', width:120,align:'center',xtype: 'numbercolumn', format:'0.00',summaryType: 'sum',
					         summaryRenderer: function(value, summaryData, dataIndex) {
				                return  '合计 :' + value ;
				            }
				        }
			        ]},
			         { text: '应发总奖金',dataIndex: 'reward',width:120,align:'center',xtype: 'numbercolumn', format:'0.00',summaryType: 'sum',
						  summaryRenderer: function(value, summaryData, dataIndex) {
			                return '合计：' + value ;
			            }
			        },
			        { text: '实发总奖金',dataIndex: 'actualreward',width:120,align:'center',xtype: 'numbercolumn', format:'0.00',summaryType: 'sum',
						  summaryRenderer: function(value, summaryData, dataIndex) {
			                return '合计：' + value ;
			            },
			           editor: {
			                xtype: 'textfield',
			                allowBlank: false
			            }
			        },
			        { text: '日期', dataIndex: 'date',width:70,align:'center'}
			     ],
			     tbar: [
					  { xtype: 'button', text: '保存修改',handler: savareward,icon: 'Ext/restful/images/sava.png'
					  }
				],
			     listeners: {  
			     	     'itemdblclick':function(view,record,mode,index,e) {
					     	        var emp=record.get('employeeid');
		                         	var date=record.get('date');
		                       
					                 var mygrid1=Ext.create('Ext.grid.Panel', {
									    id:'mygrid_2898',
									    height: 215,
										width: 990,
									    columnLines:true,
									    store:'PersonJobdetailStore',
									    columns: [
											    { text: '序号', width:50,align:'center',xtype: 'rownumberer'},
											    { text: '名称', dataIndex: 'name', width:130,align:'center'},
											    { text: '所属项目', dataIndex:'job.name', width:150,align:'center'},
										        { text: '开始时间', dataIndex: 'startdate', width:150,align:'center',xtype: 'datecolumn',   format:'Y-m-d'},
										        { text: '计划完成时间',  dataIndex: 'planCompleteDate',  width:150,align:'center',xtype: 'datecolumn',   format:'Y-m-d' },
										        { text: '完成时间',  dataIndex: 'actualCompleteDate',  width:150,align:'center',xtype: 'datecolumn',   format:'Y-m-d' },
										        { text: '得分',dataIndex: 'actualcore', width:50,align:'center' },
										        { text: '状态', dataIndex: 'state',  width:80,align:'center',renderer: function(value){
															 if (value === 2) {
																	 return '<span style="color:green;">办理中</span>';
															 }if (value ===1) {
																	  return '<span style="color:purple;">未办理</span>'; 
															 }if (value === 3) {
																	 return '<span style="color:red;">结束</span>';
															 }	
													}					 
										        },
										        { text: '要求', dataIndex: 'jobRequirement', width:300,align:'center'}
										     
									    	 ]
									    	})
										var win = new Ext.Window({
														        title :'项目化工作详情',
															    width : 1000,
															    height : 530,
						                    					closable : true,
						                   					    draggable : true,
															    frame:true,
															    modal: true,
															    minimizable:true,
						       								    maximizable:true, 
						       								    layout : 'fit',
						       								    plain : true,
						       								    items: [ mygrid1 ],
						       								      buttons : [{
																		text : "确定",
																			handler : function() {	
																					win.close();
																			}												
																		},{text : "取消",
																		 handler : function() {	
																					win.close();	
																			 }	
																	}]
																})
									//此处为加载条件
								  Ext.getCmp('mygrid_2898').getStore().on('beforeload', function (store, options) {
		                            	 var new_params = {searchemp:emp,searchdate:date};
		                            	 Ext.apply(store.proxy.extraParams, new_params);
		                		  });							
						  	     Ext.getCmp('mygrid_2898').getStore().reload();
								  win.show();									 

			     	     }
			   }
		  });
		  
		this.callParent(arguments);
  }
})
 function savareward() {
 	var grid=this.ownerCt.ownerCt;
		var selections = grid.getSelectionModel().getSelection();
			if(selections){
					if(selections.length==0){
							Ext.MessageBox.alert("提示","请检查是否选中所修改行！");
							}else{   
									var ids=[]; var actualrewards=[];
									for(var i=0;i<selections.length;i++){
										var record = selections[i];
										actualrewards.push(record.get("actualreward"));
										ids.push(record.get("id"));
										
									}
							Ext.Ajax.request({
										url : 'performance_editreward',
										success : function() {
//										 Ext.getCmp('performanceGridView').getStore().on('beforeload', function (store, options) {
//                                     	  var new_params = {searchValue:Ext.util.Format.date(searchValue, 'Y-m')}
//                                    	  Ext.apply(store.proxy.extraParams, new_params);
//                                  	   });
											Ext.MessageBox.alert("提示", "保存成功！");
											grid.getSelectionModel().deselectAll();
									 		grid.getStore().reload();	
									 		
										},
											failure : function() {
												Ext.MessageBox.alert("提示", "保存失败！");
											},
											params : {
												    ids:ids,
												    actualrewards:actualrewards
												   
												}
									});	
							}
					}	
 	
 }
